const http = require("http");
const path = require("path");
const fs = require("fs");

http.createServer((req,res)=>{
    if(req.url =="/"){
        var filePath = path.join(__dirname, "/test.html");
        var fileContent = fs.readFileSync(filePath);
        res.writeHead(200, {"Content-Type":"text/html"});
        res.write(fileContent);
        res.end();
    }
    else if(req.url == "/getdata"){
        var arr = [
            {userName: "zhangsan", age: 20},
            {userName: "lisi", age: 23}
        ]
        var jsonStr = JSON.stringify(arr);
        res.writeHead(200, {"Content-Type": "text/plain"});
        res.write(jsonStr);
        res.end();
    }
    
}).listen(8083);
console.log("server is listening 8083")